<?php $this->load->view('inc/header'); ?>

<!--one colunm-->
<div class="grid_12" style="background-color:#CCCCCC; padding-top:20px; padding-bottom:15px;">
<div class="grid_12 alpha" id="one_cols1">
	<div id="topic"><img src="<?=base_url()?>images/graphic/chart.png" style="vertical-align:middle;"/>&nbsp;<?=$topic?></div>
</div>
<div class="grid_12 alpha"  id="one_cols2">
	<div id="body_stat" style="padding-left:20px; font-size:small;">
    <!-- member div-->
    	<div id="member_body" style="border-bottom:thin dotted #999999; width:870px; margin-bottom:15px;">
        	<!-- query count of member -->
        	<?php
				$member = $this->db->get('membership');
				$count_member = $member->num_rows();
			?>
            <!-- query count of member -->
        	<?php
				/*male*/
				$this->db->where('gender','male');
				$member_q1 = $this->db->get('membership');
				$count_gender = $member_q1->num_rows();	
				
				/*female*/
				$this->db->where('gender','female');
				$member_q2 = $this->db->get('membership');
				$count_gender2 = $member_q2->num_rows();	
				
				/*percen*/
				$m_sum = ($count_gender*100)/$count_member;
				$fm_sum = ($count_gender2*100)/$count_member;
			?>
            <script type="text/javascript">
			//hide chart on load
			$(document).ready(function(){
				$('#container_charts_member').hide();
			});
			
			//chart		
			var chart;
			$(document).ready(function() {
			//toggle click
				$('#member_charts').click(function(){
					$('#container_charts_member').slideToggle('slow');
			
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container_charts_member'
					},
					title: {
						text: 'Percentage of total membership, KMCS'
					},
					plotArea: {
						shadow: null,
						borderWidth: null,
						backgroundColor: null
					},
					tooltip: {
						formatter: function() {
							return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
						}
					},
					plotOptions: {
						pie: {
							allowPointSelect: true,
							cursor: 'pointer',
							dataLabels: {
								enabled: true,
								color: '#000000',
								connectorColor: '#000000',
								formatter: function() {
									return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
								}
							}
						}
					},
				    series: [{
						type: 'pie',
						name: 'Browser share',
						data: [
							['Female',   <?=$fm_sum?>],
							['Male',       <?=$m_sum?>],
							/*{
								name: 'Administrator',    
								y: 12.8,
								sliced: true,
								selected: true
							}*/
						]
					}]
				});
			});
		});
		</script>

        	
            <div id="report" style="margin-bottom:10px;">
            	<h3><img src="<?=base_url()?>images/graphic/users.png" style="vertical-align:middle;"/>&nbsp;Member Statistics&nbsp;(<?=$count_member?>)</h3>
            	<ul>
                    <li><img src="<?=base_url()?>images/graphic/user-white.png" style="vertical-align:middle;"/>&nbsp;Male: <?=$count_gender?></li>
                    <li><img src="<?=base_url()?>images/graphic/user-white-female.png" style="vertical-align:middle;"/>&nbsp;Female: <?=$count_gender2?></li>
                </ul>  
            </div>
            <div id="member_charts" style="font-size:11px; background:#E5E5E5; cursor:pointer; padding:1px; text-align:center; width:868px;">&nbsp;แสดงแผนภูมิวงกลม (อัตราส่วนผู้ใช้งานในระบบ)&nbsp;<img src="<?=base_url()?>images/graphic/cursor-small.png" style="vertical-align:middle;"/></div>
            <div id="container_charts_member" style="width: 800px; height: 400px;"></div>  
</div>
<!-- close -->

<!-- orgs div -->
<div id="org_body" style="border-bottom:thin dotted #999999; width:870px; margin-bottom:15px;">
        	<!-- query count of organization -->
        	<?php
				//get category organization counts.
				$organization = $this->db->get('organization');
				$count_orgs = $organization->num_rows();
				
				//get all count of organization.
				$c_organization = $this->db->get('content_of_organization');
				$count_news_orgs = $c_organization->num_rows();
			?>
            
            <script type="text/javascript">
			//hide chart on load
			$(document).ready(function(){
				$('#container_charts_organization').hide();
				//toggle click
				
				
			});
			
			//chart		
			var chart;
			$(document).ready(function() {
			$('#organization_charts').click(function(){
					$('#container_charts_organization').slideToggle('slow');
			
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container_charts_organization'
					},
					title: {
						text: 'แสดงอัตราร้อยละแบ่งตามประเภทหน่วยงาน, ข่าวสารทั้งหมดปัจจุบัน = <?=$count_news_orgs?> รายการ'
					},
					plotArea: {
						shadow: null,
						borderWidth: null,
						backgroundColor: null
					},
					tooltip: {
						formatter: function() {
							return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
						}
					},
					plotOptions: {
						pie: {
							allowPointSelect: true,
							cursor: 'pointer',
							dataLabels: {
								enabled: true,
								color: '#000000',
								connectorColor: '#000000',
								formatter: function() {
									return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
								}
							},showInLegend: true

						}
					},
				    series: [{
						type: 'pie',
						name: 'Organization News',
						data: [
						
						//query php
							<?php	
								//get count news & do formular
								$q_list_org = $this->db->query('select organization.org_name, count(content_of_organization.org_id) as c_news from content_of_organization, organization where content_of_organization.org_id=organization.org_id group by content_of_organization.org_id');
								foreach($q_list_org->result() as $q_orgs){
									$summation_of_news = ($q_orgs->c_news*100)/$count_news_orgs;
							?>
							['<?=$q_orgs->org_name?>',   <?=$summation_of_news?>],
							<?php
							}	//end foreach
							?>
							/*{
								name: 'Administrator',    
								y: 12.8,
								sliced: true,
								selected: true
							}*/
						]
					}]
				});
			});
		});		
		</script>

        	
            <div id="report" style="margin-bottom:10px;">
            	<h3><img src="<?=base_url()?>images/graphic/home.png" style="vertical-align:text-bottom;"/>&nbsp;Organization Statistics&nbsp;(<?=$count_orgs?>)</h3>
            	<ol>
                	<?php
						$q_org_list = $this->db->get('organization');
						foreach($q_org_list->result() as $qq){
					?>
                    <li><?=$qq->org_name?>&nbsp;(<?=$qq->org_description?>)</li> 
                    <?php
					} //end foreach
					?>
                </ol>  
            </div>
            <div id="organization_charts" style="font-size:11px; background:#D0D9F4; cursor:pointer; padding:1px; text-align:center; width:868px;">&nbsp;แสดงแผนภูมิวงกลม (อัตราส่วนของจำนวนข่าวสารในกลุ่มหน่วยงาน)&nbsp;<img src="<?=base_url()?>images/graphic/cursor-small.png" style="vertical-align:middle;"/></div>
            <div id="container_charts_organization" style="width: 800px; height: 400px;"></div>  
</div>
<!-- close s-->

<!-- blog div-->
    	<div id="blog_body" style="border-bottom:thin dotted #999999; width:870px; margin-bottom:15px;">
        <script type="text/javascript">
			//hide chart on load
			$(document).ready(function(){
				$('#container_charts_blog').hide();
				//toggle click
			});
			
			//chart		
			var chart;
			$(document).ready(function() {
			$('#blog_charts').click(function(){
					$('#container_charts_blog').toggle();
			
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container_charts_blog',
						defaultSeriesType: 'column',
						margin: [ 50, 50, 100, 80]
					},
					title: {
						text: 'Total Blog\'s per Category'
					},
					xAxis: {
						categories: [
						<?php
							$b_charts_q = $this->db->query('select blog_category.category_name, count(blog.blog_id) as c_blogs from blog_category, blog where blog_category.b_category_id=blog.b_category_id group by blog.b_category_id');
							foreach($b_charts_q->result() as $b_c_query){
						?>
							'<?=$b_c_query->category_name?>', 
						<?php
						}
						?>
						],
						labels: {
							rotation: -45,
							align: 'right',
							style: {
								 font: 'normal 11px Verdana, sans-serif'
							}
						}
					},
					yAxis: {
						min: 0,
						title: {
							text: 'จำนวนเลข = จำนวนบล็อก'
						}
					},
					legend: {
						enabled: false
					},
					credits: {
						enabled: true
					},
					plotOptions: {
						 series: {
							cursor: 'pointer',
							borderRadius: 2 ,
							colorByPoint: true,
						}
					},
					tooltip: {
						formatter: function() {
							return '<b>'+'Category: '+ this.x +'</b><br/>'+
								 'จำนวนบล็อกในรายการนี้: '+ Highcharts.numberFormat(this.y, 0, ',') +
								 ' รายการ';
						}
					},
				        series: [{
						name: 'Blogs',
						//query date php
						data: [
						<?php
							$b_charts_q = $this->db->query('select blog_category.category_name, count(blog.blog_id) as c_blogs from blog_category, blog where blog_category.b_category_id=blog.b_category_id group by blog.b_category_id');
							foreach($b_charts_q->result() as $b_c_query){
						?>
							<?=$b_c_query->c_blogs?>,	//data arrays
						<?php
						}
						?>	
						],
						
						dataLabels: {
							enabled: true,
							rotation: -90,
							color: '#FFFFFF',
							align: 'right',
							x: -3,
							y: 10,
							formatter: function() {
								return this.y;
							},
							style: {
								font: 'normal 13px Verdana, sans-serif'
							}
						}			
					}]
				});
				
				
			});
		});		
		</script>

        	<!-- query blog -->
        	<?php
				/*count all blogs*/
				$blogs_content = $this->db->get('blog');
				$count_b_content = $blogs_content->num_rows();

				/*count of cate*/
				$blogs_cate = $this->db->get('blog_category');
				$count_b_cate = $blogs_cate->num_rows();	
				
				/*count of comment*/
				$blogs_com = $this->db->get('blog_comment');
				$count_b_com = $blogs_com->num_rows();
				
				/*count of votes*/
				$blogs_vote = $this->db->get('blog_vote');
				$count_b_vote = $blogs_vote->num_rows();	
				
				/*count of votes (like)*/
				$this->db->where('like_vote','1');
				$blogs_vote_like = $this->db->get('blog_vote');
				$count_b_vote_like = $blogs_vote_like->num_rows();	
				
				/*count of votes (dislike)*/
				$this->db->where('dislike_vote','1');
				$blogs_vote_dlike = $this->db->get('blog_vote');
				$count_b_vote_dlike = $blogs_vote_dlike->num_rows();
			?>
            
            <div id="report" style="margin-bottom:10px;">
            	<h3><img src="<?=base_url()?>images/graphic/blogs.png" style="vertical-align:middle;"/>&nbsp;Blogs Statistics</h3>
            	<ul>
                    <li>Total of blogs: <?=$count_b_content?></li>
                    <li>Blog Categorys: <?=$count_b_cate?></li>
                    	<ol>
                        	<?php
								$blogs_cate_list = $this->db->get('blog_category');
								foreach($blogs_cate_list->result() as $b_c_list){
							?>
                        	<li><a href="<?=site_url()?>/blog/category/<?=$b_c_list->b_category_id?>"><?=$b_c_list->category_name?></a>&nbsp;(<?=$b_c_list->category_description?>)</li>
                            <?php
							}
							?>
                        </ol>
                        <li>Total of User's Comments all blogs: <?=$count_b_com?></li>
                        <li>Total of User's Votes all blogs: <?=$count_b_vote?></li>
                        	<ul>
                            	<li><img src="<?=base_url()?>images/graphic/thumb-up.png" style="vertical-align:sub;"/> = <?=$count_b_vote_like?></li>
                                <li><img src="<?=base_url()?>images/graphic/thumb.png" style="vertical-align:middle;"/> = <?=$count_b_vote_dlike?></li>
                            </ul>
                </ul>  
            </div>
            <div id="blog_charts" style="font-size:11px; background:#E0F4C6; cursor:pointer; padding:1px; text-align:center; width:868px;">&nbsp;แสดงแผนภูมิวงกลม (อัตราส่วนจำนวนบล็อกต่อประเภทบล็อก)&nbsp;<img src="<?=base_url()?>images/graphic/cursor-small.png" style="vertical-align:middle;"/></div>
            <div id="container_charts_blog" style="width: 800px; height: 400px;"></div>
	</div>
<!-- close -->

<!-- cops div-->
    	<div id="cops_body" style="border-bottom:thin dotted #999999; width:870px; margin-bottom:15px;">
        	<!-- query count of member -->
        	<?php
				//create cop group
				$query_c_create = $this->db->get('cops_group');
				$count_c_create = $query_c_create->num_rows();
				
				//join group
				$query_c_group_in = $this->db->get('cops_group_in');
				$count_c_group_in = $query_c_group_in->num_rows();
				
				//cops files
				$query_c_files = $this->db->get('cops_files');
				$count_c_files = $query_c_files->num_rows();
				
				//cops discuss
				$query_c_discuss = $this->db->get('cops_discuss');
				$count_c_discuss = $query_c_discuss->num_rows();
				
				$overall = $count_c_create+$count_c_group_in+$count_c_files+$count_c_discuss;
				
				$c1 = ($count_c_create*100)/$overall;
				$c2 = ($count_c_group_in*100)/$overall;
				$c3 = ($count_c_files*100)/$overall;
				$c4 = ($count_c_discuss*100)/$overall;
			?>
            <script type="text/javascript">
			//hide chart on load
			$(document).ready(function(){
				$('#container_charts_cops').hide();
			});
			
			//chart		
			var chart;
			$(document).ready(function() {
			//toggle click
				$('#cops_charts').click(function(){
					$('#container_charts_cops').slideToggle('slow');
			
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container_charts_cops'
					},
					title: {
						text: 'Percentage of total membership, KMCS'
					},
					plotArea: {
						shadow: null,
						borderWidth: null,
						backgroundColor: null
					},
					tooltip: {
						formatter: function() {
							return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
						}
					},
					plotOptions: {
						pie: {
							allowPointSelect: true,
							cursor: 'pointer',
							dataLabels: {
								enabled: true,
								color: '#000000',
								connectorColor: '#000000',
								formatter: function() {
									return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
								}
							},showInLegend: true

						}
					},
				    series: [{
						type: 'pie',
						name: 'Cops Chart',
						data: [
							['ข้อคิดเห็น',   <?=number_format($c4,2)?>],
							['ไฟล์',       <?=number_format($c3,2)?>],
							['การเข้าร่วมกลุ่ม',       <?=number_format($c2,2)?>],
							{
								name: 'กลุ่มที่ถูกสร้าง',    
								y: <?=number_format($c1,2)?>,
								sliced: true,
								selected: true
							}
						]
					}]
				});
			});
		});
		</script>

            <div id="report" style="margin-bottom:10px;">
            	<h3><img src="<?=base_url()?>images/graphic/light-bulb.png" style="vertical-align:middle;"/>&nbsp;Cops Statistics&nbsp;(<?=$count_c_create?>)</h3>
            </div>
            <div id="cops_charts" style="font-size:11px; background:#D9DC94; cursor:pointer; padding:1px; text-align:center; width:868px;">&nbsp;แสดงแผนภูมิวงกลม (อัตราส่วนกิจกรรมในส่วน cops)&nbsp;<img src="<?=base_url()?>images/graphic/cursor-small.png" style="vertical-align:middle;"/></div>
            <div id="container_charts_cops" style="width: 800px; height: 400px;"></div>  
</div>
<!-- close -->


</div>
</div>

<div class="grid_12 alpha" id="one_cols3"></div>
</div>
<div class="clear"></div>
<!--end one column-->

<?php $this->load->view('inc/footer'); ?>